<template>
  <div class="social-container">
    <div
      class="box"
      @click="handleClick('wechat')">
      <wechat class="logo"/>
      <p class="title">微信</p>
    </div>
    <div
      class="box"
      @click="handleClick('tencent')">
      <qq class="logo" />
      <p class="title">QQ</p>
    </div>
    <div
      class="box"
      @click="handleClick('gitee')">
      <gitee class="logo" />
      <p class="title">Gitee</p>
    </div>
    <div
      class="box"
      @click="handleClick('dingding')">
      <dingding class="logo" />
      <p class="title">钉钉</p>
    </div>
    <div
      class="box"
      @click="handleClick('wework')">
      <dingding class="logo" />
      <p class="title">企业微信</p>
    </div>
  </div>
</template>

<script>
import { openWindow } from '@/utils/util'
import { wechat, qq, dingding, gitee } from '@/core/icons'
export default {
  name: 'ThirdloginVue',
  components: {
    wechat,
    qq,
    dingding,
    gitee
  },
  methods: {
    handleClick (thirdpart) {
      let appid, client_id, redirect_uri, url
      redirect_uri = encodeURIComponent(window.location.origin + '/authredirect')
      console.log(redirect_uri, 'redirect_uri')
      if (thirdpart === 'wechat') {
        appid = 'wxd1678d3f83b1d83a'
        url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=WX-LOGIN&response_type=code&scope=snsapi_login#wechat_redirect'
      } else if (thirdpart === 'tencent') {
        client_id = '101322838'
        url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=QQ-LOGIN&client_id=' + client_id + '&redirect_uri=' + redirect_uri
      } else if (thirdpart === 'gitee') {
        client_id = 'bc3b49fdcde3aec5dab82af25f168e1bd4c190694cb8d72fd72a282539a37535'
        url = 'https://gitee.com/oauth/authorize?response_type=code&client_id=' + client_id + '&state=GITEE-LOGIN&redirect_uri=' + redirect_uri
      } else if (thirdpart === 'dingding') {
        client_id = 'dingoa8xagn3o06b2qjzgc'
        url = 'https://oapi.dingtalk.com/connect/qrconnect?response_type=code&appid=' + client_id + '&state=DING-LOGIN&redirect_uri=' + redirect_uri + '&scope=snsapi_login'
      } else if (thirdpart === 'wework') {
        client_id = 'ww6afb8c4a10c4ec39'
        const agentId = '1000003'
        // url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${client_id}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=WEWORK-LOGIN#wechat_redirect`
        url = `https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=${client_id}&agentid=${agentId}&redirect_uri=${redirect_uri}&state=WEWORK-LOGIN`
      }
      openWindow(url, thirdpart, 540, 540)
    }
  }
}
</script>

<style lang="less" scoped>
  .social-container {
    margin: 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-around;

  .box {
    cursor: pointer;
  }

  .iconfont {
    color: #fff;
    font-size: 30px;
  }

  .container {
    display: inline-block;
    width: 50px;
    height:50px;
    line-height: 50px;
    text-align: center;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .title {
    text-align: center;
  }
    .logo{
      width: 50px;
      height:50px;
    }
  }
</style>
